import axios from 'axios';
import { UserVo } from '@/api/user';
import { interfaceDTO } from '@/api/interface';

export interface ChargeTypeVO {
  chargeType: string;
  chargeTypeName: string;
}

export interface DepartmentVO {
  departmentId: string;
  departmentName: string;
}

export interface InvoiceTypeVO {
  invoiceType: string;
  invoiceTypeName: string;
}

export interface PayWayVO {
  payWay: string;
  payWayName: string;
}

export interface RuleItemVO {
  id: string;
  creditColumn: string;
  creditColumnName: string;
  debitColumn: string;
  debitColumnName: string;
  headId: string;
  subjectCode: string;
  subjectName: string;
  summary: string;
  voucherRule: string;
}

export interface VoucherRuleDTO {
  accountSetId: string;
  accountSetName: string;
  bankCode: string;
  bodyType: string;
  chargeTypeList: ChargeTypeVO[];
  departmentList: DepartmentVO[];
  enableFlag: string;
  invoiceTypeList: InvoiceTypeVO[];
  name: string;
  payWayList: PayWayVO[];
  ruleItemList: RuleItemVO[];
  typeId: string;
  typeName: string;
  id: string;
}
export interface ResultVO {
  id: string;
  name: string;
}
export interface AccountParams {
  page: number;
  rows: number;
  keywords?: string;
}
export interface AccountSubject2AssisteComputDTO {
  accountSetId: string;
  assistComputId: string;
  subjectId: string;
  id: string;
}

export function createRule(params: VoucherRuleDTO) {
  return axios.post('share/voucher/rule/create', params);
}
export function detailRule(ruleId: string) {
  return axios.get<VoucherRuleDTO>(`share/voucher/rule/detail/${ruleId}`);
}
export function updateStatusRule(id: string, status: string) {
  return axios.post(`share/voucher/rule/updateStatus/${id}/${status}`);
}
export function listRule(type: string) {
  return axios.get<VoucherRuleDTO[]>(`share/voucher/rule/list?typeId=${type}`);
}
export function updateRule(params: VoucherRuleDTO) {
  return axios.post('share/voucher/rule/update', params);
}
// 费用类型
export function chargeTypeList(name: string) {
  return axios.get<ResultVO[]>(
    `share/voucher/helper/chargeType/list?name=${name}`
  );
}
// 往来单位
export function contractorList() {
  return axios.get<ResultVO[]>(`share/voucher/helper/contractor/list`);
}
// 往来员工/个人
export function contractorAndStaffList(name: string) {
  return axios.post<ResultVO[]>(
    `share/voucher/helper/contractorAndStaff/list`,
    { keyWords: name }
  );
}
// 部门
export function departmentList() {
  return axios.get<ResultVO[]>(`share/voucher/helper/department/list`);
}
// 付款方式
export function payWayList() {
  return axios.get<ResultVO[]>(`share/voucher/helper/payWay/list`);
}
// 发票类型
export function invoiceTypeList() {
  return axios.get<ResultVO[]>(`share/invoiceType/list`);
}
// 分页查询科目-能带出相应辅助核算项
export function accountSetList(data: AccountParams) {
  return axios.post<any>(`share/voucher/helper/accountSubject/list`, data);
}
// 查询科目树-能带出相应辅助核算项
export function accountSubjectAll(keyWords: string) {
  return axios.post<any>(
    `share/voucher/helper/accountSubject/all?keyWords=${keyWords}`
  );
}
// 字段查询
export function columnList() {
  return axios.get<ResultVO[]>(`share/voucher/helper/column/list`);
}
// 创建辅助核算项
export function createAssistComput2AccountSubject(
  data: AccountSubject2AssisteComputDTO[]
) {
  return axios.post(`share/voucher/helper/createAssistComput2AccountSubject`, {
    accountSubject2AssisteComputAddDTOList: data,
  });
}
// 删除辅助核算项
export function deleteAssistComput2AccountSubject(id: string) {
  return axios.post(
    `share/voucher/helper/deleteAssistComput2AccountSubject/${id}`
  );
}
// 根据科目获取辅助核算项
export function getAssistComputs(subjectId: string) {
  return axios.get<any>(`share/voucher/helper/getAssistComputs/${subjectId}`);
}
// 根据科目获取辅助核算项
export function updateAssistComput2AccountSubject(
  data: AccountSubject2AssisteComputDTO[]
) {
  return axios.post(`share/voucher/helper/updateAssistComput2AccountSubject`, {
    accountSubject2AssisteComputUpdateDTOList: data,
  });
}

export interface PreVoucherQueryDTO {
  page: number;
  rows: number;
  voucherId: string;
}
export interface PreVoucherVO {
  id: string;
  /**
   * 凭证预报文
   */
  preVoucherContent: string;

  /**
   * OA单据号
   */
  auditNumber: string;

  /**
   * 业务凭证号
   */
  bizVoucherNumber: string;

  /**
   * 是否推送TPlus成功
   */
  sucessFlag: string;
}
export interface RowsVo {
  rows: PreVoucherVO[];
  total: number;
}
export function preVoucherQuery(data: PreVoucherQueryDTO) {
  return axios.post<RowsVo>(`share/voucher/helper/preVoucher/query`, data);
}
export function preVoucherDetail(id: string) {
  return axios.get<PreVoucherVO>(`share/voucher/helper/preVoucherDetail/${id}`);
}
export function preVoucherPush(voucherId: string) {
  return axios.post(`share/voucher/helper/preVoucher/push/${voucherId}`);
}
export interface OperationLog {
  /** 审核编号 (Audit Number) */
  auditNumber: string | null;
  /** 授权控制标志 (Authorization Control Flag) */
  authControl: boolean;
  /** 业务凭证编号 (Business Voucher Number) */
  bizVoucherNumber: string | null;
  /** 创建组织ID (Create Organization ID) */
  createOrgId: string | null;
  /** 创建组织名称 (Create Organization Name) */
  createOrgName: string | null;
  /** 创建时间 (Creation Time) */
  createTime: string;
  /** 创建者ID (Creator ID) */
  creator: string | null;
  /** 创建者姓名 (Creator Name) */
  creatorName: string | null;
  /** 删除标志 (Delete Flag) - "0"表示未删除 */
  deleteFlag: string;
  /** 有权限的组织集合 (Authorized Organizations Collection) */
  hasAuthCreateOrgCollection: any[]; // 根据实际数据结构替换 any[]
  /** 有权限的创建者集合 (Authorized Creators Collection) */
  hasAuthCreatorCollection: any[]; // 根据实际数据结构替换 any[]
  /** 记录唯一ID (Unique Record ID) */
  id: string;
  /** 日志内容 (Log Content) - 包含错误信息的JSON字符串 */
  logContent: string; // 实际是包含错误详细信息的JSON
  /** 新版本时间 (New Version Timestamp) */
  newVersionTime: string | null;
  /** 操作者ID (Operator ID) */
  operator: string | null;
  /** 操作者姓名 (Operator Name) */
  operatorName: string | null;
  /** 操作成功标志 (Success Flag) - "0"表示失败 */
  sucessFlag: string;
  /** 租户ID (Tenant ID) */
  tenantId: string | null;
  /** 版本时间 (Version Timestamp) */
  versionTime: string | null;
  /** 凭证编号 (Voucher Number) */
  voucherNumber: string;
}
export function push2TplusLog(voucherId: string) {
  return axios.get<OperationLog[]>(
    `share/voucher/helper/push2TplusLog/${voucherId}`
  );
}
export function preVoucherEdit(data: PreVoucherVO) {
  return axios.post(`share/voucher/helper/preVoucher/edit`, data);
}
